home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / tiff256.zip / TIF_DEMO.C < prev    next >
C/C++ Source or Header  |  1992-07-04  |  14KB  |  390 lines

  1. /*.............................. TIF_DEMO.C ................. 7-4-92 .......*/
  2. /* This program demonstrates the use of the TIFF reading and display        */
  3. /* capabilities of the VSA256 Version 1.1 Graphics Library and the          */
  4. /* TIFF256 Graphics Library Extensions Version 1.0                          */
  5. /*                                                                          */
  6. /* TO RUN:  - Enter VESA video mode                                         */
  7. /*          - Hit any key to continue or ESC to exit program                */
  8. /*          - Enter x,y image origin                                        */
  9. /*          - Enter full TIFF file name including path and extension        */
  10. /*          - Image is now drawn                                            */
  11. /*          - Hit any key to repeat sequence or ESC to exit program         */
  12. /*                                                                          */
  13. /* NOTE: Sometimes your input is not visible, depending on the Color Look   */
  14. /*       Up Table that is active due to last image ploted.  Keep typing,    */
  15. /*       your input will be accepted anyway.                                */
  16. /*..........................................................................*/
  17.  
  18. #include <io.h>             /* Required to support TIFF256 Graphics Library */
  19. #include <stdio.h>          /* Required to support TIFF256 Graphics Library */
  20. #include <fcntl.h>          /* Required to support TIFF256 Graphics Library */
  21. #include<math.h>
  22. #include<limits.h>
  23.  
  24. #include "tiff.h"           /* Required to support TIFF256 Graphics Library */
  25. #include "vsa.h"            /* Required to support VSA256 Graphics Library  */
  26.  
  27. extern unsigned _stklen = 10000;        /* This is for Borland C Only ! */
  28.  
  29. void main()
  30. {
  31.     int a,b,r0,c0,bug;
  32.     unsigned vmode,xx,yy,x0,y0,ya;
  33.     char filename[100],key;
  34.     ya = 4;
  35. /*..........................................................................*/
  36. /*               Initialize video mode and VSA256 environment.              */
  37. /*               Valid modes are: 100h, 101h, 103h, and 105h.               */
  38. /*..........................................................................*/
  39.     bug = 0;
  40.     printf("\n");
  41.     printf("Input VESA standard Video Mode (hex)\n");
  42.     printf("(100, 101, 103, or 105): ");
  43.     scanf("%x",&vmode);
  44.     if(vmode == 0x666)
  45.         {
  46.             printf("Welcome to the Trident Bug Patch for Video Mode 103\n");
  47.             printf("Please enter Character Height in pixels (Try 16): ");
  48.             scanf("%d",&bug);
  49.             vmode = 0x103;
  50.         }
  51.     vsa_init(vmode);
  52.     if(bug != 0)
  53.         YCharSize = bug;
  54.     xx = XResolution;
  55.     yy = YResolution;
  56.     vsa_set_text_cursor_mode(1);
  57.     r0 = 0.85*YCharResolution;
  58.     c0 = 0.5*XCharResolution - 17;
  59. /*..........................................................................*/
  60. /*             Draw color look up table at bottom of screen.                */
  61. /*..........................................................................*/
  62.     rainbow_lut();
  63.     tf_set_prime_colors();
  64. HERE:
  65.     a = .125*xx;
  66.     b = .91*yy;
  67.     color_bar(a,b);
  68. /*..........................................................................*/
  69. /*                   Draw Prime Colors at screen right.                     */
  70. /*..........................................................................*/
  71.     a = xx - 11*XCharSize;
  72.     b = ya*YCharSize;
  73.     prime_list(a,b);
  74. /*..........................................................................*/
  75. /*                          Draw a banner                                   */
  76. /*..........................................................................*/
  77.     banner(ya);
  78. /*..........................................................................*/
  79. /*                         Outline Screen                                   */
  80. /*..........................................................................*/
  81.     vsa_set_color(TF_Red);
  82.     vsa_move_to(0,0);
  83.     vsa_rect(xx-1,yy-1);
  84.     vsa_move_to(1,1);
  85.     vsa_rect(xx-2,yy-2);
  86. /*..........................................................................*/
  87. /*         Wait for any key to continue; if ESC key, quit program.          */
  88. /*..........................................................................*/
  89.     vsa_write_string(r0,c0,TF_Yellow,
  90.                                      "Press ESC to exit, Any other key to continue ...   ");
  91.     key = getch();
  92.     if(key == 27)
  93.         goto BAIL;
  94. /*..........................................................................*/
  95. /*                   Get picture start coordinates.                         */
  96. /*..........................................................................*/
  97.     vsa_set_text_color(TF_Red);
  98.     vsa_set_text_cursor(r0,c0);
  99.     vsa_write_string_alt("                                                   ");
  100.     vsa_set_text_cursor(r0,c0);
  101.     vsa_write_string_alt("Input picture origin (x0,y0): ");
  102.     scanf("%d,%d",&x0,&y0);
  103.     x0 += 5;
  104.     y0 += ya*YCharSize+4;
  105. /*..........................................................................*/
  106. /*                            Open TIFF File.                               */
  107. /*..........................................................................*/
  108. FILENAME:
  109.     vsa_set_text_color(TF_Green);
  110.     vsa_set_text_cursor(r0,c0);
  111.     vsa_write_string_alt("                                                   ");
  112.     vsa_set_text_cursor(r0,c0);
  113.     vsa_write_string_alt("Input full Filename: ");
  114.     scanf("%s",filename);
  115.   if(tf_open_file(filename) == -1)
  116.         goto FILENAME;
  117. /*..........................................................................*/
  118. /*                      Get TIFF File information.                          */
  119. /*..........................................................................*/
  120.     if(tf_get_file_info() == 1)
  121.         {
  122.             printf("Error\n");
  123.             return;
  124.         }
  125. /*..........................................................................*/
  126. /*  Prior to reading the image information, set defaults for all globals.   */
  127. /*..........................................................................*/
  128.     tf_set_defaults();
  129. /*..........................................................................*/
  130. /* Read image information.  Globals are set, pointers to image data are     */
  131. /* extracted.                                                               */
  132. /*..........................................................................*/
  133.     if(tf_read_ifd() == 1)
  134.         goto NOTSUPPORTED;
  135. /*..........................................................................*/
  136. /*                 Display TIFF image starting at (x0,y0).                  */
  137. /*..........................................................................*/
  138.     tf_display_image(x0,y0);
  139. /*..........................................................................*/
  140. /*                 Restore Prime Color Values.                              */
  141. /*..........................................................................*/
  142.     tf_set_prime_colors();
  143. /*..........................................................................*/
  144. /*                            Frame new image.                              */
  145. /*..........................................................................*/
  146.     vsa_set_color(TF_White);
  147.     vsa_move_to(x0-2,y0-2);
  148.     vsa_rect(x0+(unsigned)TF_ImageWidth+1,y0+(unsigned)TF_ImageLength+1);
  149.     vsa_set_color(TF_Black);
  150.     vsa_move_to(x0-1,y0-1);
  151.     vsa_rect(x0+(unsigned)TF_ImageWidth,y0+(unsigned)TF_ImageLength);
  152. /*..........................................................................*/
  153. /*                 Update Image Statistics                                  */
  154. /*..........................................................................*/
  155.     a = .70*xx;
  156.     b = .60*yy;
  157.     image_stats(a,b);
  158. /*..........................................................................*/
  159. /*                        Close opened TIFF file.                           */
  160. /*..........................................................................*/
  161. NOTSUPPORTED:
  162.     tf_close_file();
  163.     goto HERE;
  164. /*..........................................................................*/
  165. /*                       Restore text video mode and Bail Out.              */
  166. /*..........................................................................*/
  167. BAIL:
  168.     vsa_set_svga_mode(0x3);
  169.     tf_about();
  170.     return;                       /*.....            End main            .....*/
  171. }
  172.  
  173.  
  174. rainbow_lut()
  175. {
  176.     int i,start,count;
  177.     unsigned char color_array[768];
  178.     for(i=0;i<224;i++)
  179.         {
  180.             color_array[3*i+2]=0;
  181.             color_array[3*i+1]=0;
  182.             color_array[3*i]=0;
  183.         }
  184. /*................................ RED .....................................*/
  185.     for(i=0;i<56;i++)
  186.         {
  187.                 color_array[3*i] = 63*sin((i*6.28)/112.0);
  188.         }
  189. /*............................... BLUE .....................................*/
  190.     for(i=0;i<126;i++)
  191.         {
  192.                 color_array[3*i+2] = 63*sin((i*6.28)/252.0);
  193.         }
  194. /*............................... GREEN ....................................*/
  195.     for(i=96;i<210;i++)
  196.         {
  197.                 color_array[3*i+1] = 63*sin(((i-90)*6.28)/252.0);
  198.         }
  199. /*................................ RED .....................................*/
  200.     for(i=140;i<224;i++)
  201.         {
  202.                 color_array[3*i]   = 63*sin(((i-140)*6.28)/280.0);
  203.         }
  204.     start = 32;
  205.     count = 224;
  206.     vsa_write_color_block(start,count,color_array);
  207.     return 0;
  208. }
  209.  
  210.  
  211. color_bar(x0,y0)
  212. int x0,y0;
  213. {
  214.     char text[100];
  215.     unsigned char row,col;
  216.     int i;
  217.     unsigned xx,yy,a,b;
  218.     float c;
  219.     xx = XResolution;
  220.     yy = YResolution;
  221. /*..........................................................................*/
  222. /*     Draw outline for color bar.                                          */
  223. /*..........................................................................*/
  224.     vsa_set_color(15);
  225.     vsa_move_to(x0-1,y0-1);
  226.     a = .75*xx;
  227.     b = .065*yy;
  228.     vsa_rect(x0+a+1,y0+b+1);
  229.     c = (float)a/256;
  230.     for(i=0;i<256;i++)
  231.         {
  232.             vsa_set_color((unsigned char)i);
  233.             vsa_move_to(x0+(unsigned)(i*c),y0);
  234.             vsa_rect_fill(x0+(unsigned)(c+i*c),y0+b);
  235.         }
  236.     return 0;
  237. }
  238.  
  239. prime_list(x0,y0)
  240. int x0,y0;
  241. {
  242.     unsigned char row,col;
  243.     int i;
  244.     unsigned xxx,yyy;
  245.  
  246.     xxx = x0 + 9*XCharSize;
  247.     yyy = y0;
  248.  
  249.     row = (y0)/YCharSize;
  250.     col = (x0)/XCharSize;
  251.     vsa_set_color(TF_Black);
  252.     vsa_write_string(row,col,TF_Black,"Black =  ");
  253.     vsa_move_to(xxx,yyy);
  254.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  255.  
  256.     row ++;
  257.   yyy += YCharSize;
  258.     vsa_set_color(TF_Red);
  259.     vsa_write_string(row,col,TF_Red,"Red =    ");
  260.     vsa_move_to(xxx,yyy);
  261.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  262.  
  263.     row ++;
  264.   yyy += YCharSize;
  265.     vsa_set_color(TF_Orange);
  266.     vsa_write_string(row,col,TF_Orange,"Orange = ");
  267.     vsa_move_to(xxx,yyy);
  268.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  269.  
  270.     row ++;
  271.   yyy += YCharSize;
  272.     vsa_set_color(TF_Yellow);
  273.     vsa_write_string(row,col,TF_Yellow,"Yellow = ");
  274.     vsa_move_to(xxx,yyy);
  275.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  276.  
  277.     row ++;
  278.   yyy += YCharSize;
  279.     vsa_set_color(TF_Green);
  280.     vsa_write_string(row,col,TF_Green,"Green =  ");
  281.     vsa_move_to(xxx,yyy);
  282.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  283.  
  284.     row ++;
  285.   yyy += YCharSize;
  286.     vsa_set_color(TF_Aqua);
  287.     vsa_write_string(row,col,TF_Aqua,"Aqua =   ");
  288.     vsa_move_to(xxx,yyy);
  289.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  290.  
  291.     row ++;
  292.   yyy += YCharSize;
  293.     vsa_set_color(TF_Blue);
  294.     vsa_write_string(row,col,TF_Blue,"Blue =   ");
  295.     vsa_move_to(xxx,yyy);
  296.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  297.  
  298.     row ++;
  299.   yyy += YCharSize;
  300.     vsa_set_color(TF_Violet);
  301.     vsa_write_string(row,col,TF_Violet,"Violet = ");
  302.     vsa_move_to(xxx,yyy);
  303.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  304.  
  305.     row ++;
  306.   yyy += YCharSize;
  307.     vsa_set_color(TF_White);
  308.     vsa_write_string(row,col,TF_White,"White =  ");
  309.     vsa_move_to(xxx,yyy);
  310.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  311.  
  312.     return 0;
  313. }
  314.  
  315. image_stats()
  316. {
  317.     char text[100];
  318.     unsigned char row,col;
  319.  
  320.     row = 1;
  321.     col = 39;
  322.  
  323.     sprintf(text,"Width  = %d     ",TF_ImageWidth);
  324.     vsa_write_string(row,col,TF_White,text);
  325.     row++;
  326.     sprintf(text,"Length = %d     ",TF_ImageLength);
  327.     vsa_write_string(row,col,TF_White,text);
  328.     row++;
  329.     row = 1;
  330.     col = 55;
  331.     if(TF_PhotometricInterpretation < 2)
  332.         {
  333.             vsa_write_string(row,col,TF_White,"Color Model = Bilevel or");
  334.             row++;
  335.             vsa_write_string(row,col,TF_White,"              GrayScale ");
  336.             row++;
  337.             sprintf(text,"%d Bits Per Pixel        ",TF_BitsPerSample[0]);
  338.             vsa_write_string(row,col,TF_White,text);
  339.             row++;
  340.         }
  341.     if(TF_PhotometricInterpretation == 2)
  342.         {
  343.             vsa_write_string(row,col,TF_White,"Color Model = True Color");
  344.             row++;
  345.             vsa_write_string(row,col,TF_White,"24 Bits Per Pixel       ");
  346.             row++;
  347.             vsa_write_string(row,col,TF_White,"(8 bits each R,G,B)     ");
  348.             row++;
  349.         }
  350.     if(TF_PhotometricInterpretation == 3)
  351.         {
  352.             vsa_write_string(row,col,TF_White,"Color Model = Palette   ");
  353.             row++;
  354.             sprintf(text,"%d Bits Per Pixel        ",TF_BitsPerSample[0]);
  355.             vsa_write_string(row,col,TF_White,text);
  356.             row++;
  357.             vsa_write_string(row,col,TF_White,"                        ");
  358.             row++;
  359.         }
  360.     if(TF_PhotometricInterpretation > 3)
  361.         vsa_write_string(row,col,TF_White,"Color Model = Unknown   ");
  362.     return 0;
  363. }
  364.  
  365. banner(ya)
  366. unsigned ya;
  367. {
  368.     unsigned char row,col;
  369.     char text[100];
  370.     unsigned xx,yy;
  371.     xx = XResolution;
  372.     yy = YResolution;
  373.     vsa_move_to(0,0);
  374.     vsa_set_color(TF_Red);
  375.     vsa_rect(xx-1,ya*YCharSize);
  376.     vsa_move_to(38*XCharSize,0);
  377.     vsa_line_to(38*XCharSize,ya*YCharSize);
  378.     vsa_move_to(38*XCharSize+1,0);
  379.     vsa_line_to(38*XCharSize+1,ya*YCharSize);
  380.     row = 1;
  381.     col = 2;
  382.     sprintf(text,"TIFF256 GRAPHICS LIBRARY EXTENSIONS");
  383.     vsa_write_string(row,col,TF_Green,text);
  384.     sprintf(text,"           VERSION 1.0");
  385.     vsa_write_string(row+1,col,TF_Green,text);
  386.     sprintf(text,"    Copyright Spyro Gumas 1992");
  387.     vsa_write_string(row+2,col,TF_Green,text);
  388.     return 0;
  389. }
  390.